﻿using Infrastructure.AggregateBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace Domain.Model
{
    [Table("TaskCategory")]
    public class TaskCategoryAggregate : AggregateRoot<TaskCategoryAggregate, int>
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public override int ID { get; set; }
        /// <summary>
        /// 图标
        /// </summary>
        [StringLength(2000)]
        public string Icon { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        [StringLength(200)]
        public string Title { get; set; }
        /// <summary>
        /// 副标题
        /// </summary>
        [StringLength(200)]
        public string SubTitle { get; set; }
        /// <summary>
        /// 字段数据
        /// </summary>
        [StringLength(2000)]
        public string FieldData { get; set; }
        /// <summary>
        /// 任务步骤
        /// </summary>
        public bool NeedTaskStepData { get; set; } = true;
        /// <summary>
        /// 提交数据
        /// </summary>
        public bool NeedSubField { get; set; }
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsEnable { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; }
        /// <summary>
        /// 获取字段数据
        /// </summary>
        /// <returns></returns>
        public List<TaskFieldInfo> GetNFieldData()
        {
            if (string.IsNullOrWhiteSpace(FieldData)) return null;

            return JsonConvert.DeserializeObject<List<TaskFieldInfo>>(FieldData);
        }
        /// <summary>
        /// 设置字段数据
        /// </summary>
        /// <param name="taskFieldInfos"></param>
        public void SetNFieldData(List<TaskFieldInfo> taskFieldInfos)
        {
            FieldData = JsonConvert.SerializeObject(FieldData);
        }
    }
}
